﻿<%@ Page Title="Xếp lịch điều xe" MasterPageFile="~/Admin/Site.Master" Language="C#"
    AutoEventWireup="true" CodeBehind="XepLichDieuXe.aspx.cs" Inherits="Transport.Admin.XepLichDieuXe" %>

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
    <div>
        <b>A - THÔNG TIN ĐẶT XE</b>
    </div>
    <p>
        <b>ID:</b>
        <asp:TextBox ID="txt_ID" runat="server" />
        <b>Tên đăng nhập:</b>
        <asp:TextBox ID="txt_Username" runat="server" />
        <asp:Button ID="btn_Search1" runat="server" Text="Tìm" />
    </p>
    <p>
        <b>Dịch vụ:</b>
        <asp:DropDownList ID="ddl_DV" runat="server" AutoPostBack="True" DataSourceID="EntityDataSource_DV"
            DataTextField="ten_dich_vu" DataValueField="id_dich_vu" AppendDataBoundItems="true">
            <asp:ListItem Text="Select All" Value="-1" />
        </asp:DropDownList>
        <asp:EntityDataSource ID="EntityDataSource_DV" runat="server" ConnectionString="name=transportEntities"
            DefaultContainerName="transportEntities" EnableFlattening="False" EntitySetName="dich_vu"
            EntityTypeFilter="dich_vu">
        </asp:EntityDataSource>
        <b>Tình trạng:</b>
        <asp:DropDownList ID="ddl_Status" runat="server" AutoPostBack="True" DataSourceID="EntityDataSource_Status"
            DataTextField="ten_tinh_trang" DataValueField="ma_tinh_trang_dat_xe" AppendDataBoundItems="true">
            <asp:ListItem Text="Select All" Value="-1" />
        </asp:DropDownList>
        <asp:EntityDataSource ID="EntityDataSource_Status" runat="server" ConnectionString="name=transportEntities"
            DefaultContainerName="transportEntities" EnableFlattening="False" EntitySetName="tinh_trang_dat_xe"
            EntityTypeFilter="tinh_trang_dat_xe">
        </asp:EntityDataSource>
        <b>Phương thức lái:</b>
        <asp:DropDownList ID="ddl_PTL" runat="server" AutoPostBack="True" DataSourceID="EntityDataSource_PTL"
            DataTextField="ten_phuong_thuc" DataValueField="ma_phuong_thuc" AppendDataBoundItems="true">
            <asp:ListItem Text="Select All" Value="-1" />
        </asp:DropDownList>
        <asp:EntityDataSource ID="EntityDataSource_PTL" runat="server" ConnectionString="name=transportEntities"
            DefaultContainerName="transportEntities" EnableFlattening="False" EntitySetName="phuong_thuc_lai"
            EntityTypeFilter="phuong_thuc_lai">
        </asp:EntityDataSource>
    </p>
    <p>
        <b>Lộ trình:</b>
        <asp:DropDownList ID="ddl_LT" runat="server" AutoPostBack="True" DataSourceID="EntityDataSource_LT"
            DataTextField="ten_lo_trinh" DataValueField="ma_lo_trinh" AppendDataBoundItems="true">
            <asp:ListItem Text="Select All" Value="-1" />
        </asp:DropDownList>
        <asp:EntityDataSource ID="EntityDataSource_LT" runat="server" ConnectionString="name=transportEntities"
            DefaultContainerName="transportEntities" EnableFlattening="False" EntitySetName="lo_trinh"
            EntityTypeFilter="lo_trinh">
        </asp:EntityDataSource>
        <b>Miền:</b>
        <asp:DropDownList ID="ddl_Mien" runat="server" AutoPostBack="True" DataSourceID="EntityDataSource_Mien"
            DataTextField="ten_mien" DataValueField="ma_mien" AppendDataBoundItems="true">
            <asp:ListItem Text="Select All" Value="-1" />
        </asp:DropDownList>
        <asp:EntityDataSource ID="EntityDataSource_Mien" runat="server" ConnectionString="name=transportEntities"
            DefaultContainerName="transportEntities" EnableFlattening="False" EntitySetName="miens">
        </asp:EntityDataSource>
    </p>
    <div style="zoom: 1; overflow: auto;">
        <asp:GridView ID="GridView_Resrv" runat="server" AllowPaging="True" AutoGenerateColumns="False"
            CellPadding="4" DataKeyNames="id" CellSpacing="4" DataSourceID="EntityDataSource_Rersv"
            ForeColor="#333333" GridLines="None">
            <AlternatingRowStyle BackColor="White" />
            <Columns>
                <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
                <asp:TemplateField HeaderText="Chọn">
                    <ItemTemplate>
                        <asp:CheckBox ID="cb_Select" runat="server"></asp:CheckBox>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="id" HeaderText="ID" ReadOnly="True" SortExpression="id" />
                <asp:BoundField DataField="ngay_dat" HeaderText="Ngày đặt" ReadOnly="True"  DataFormatString="{0:d}" ApplyFormatInEditMode="true"
                    SortExpression="ngay_dat" />
                <asp:BoundField DataField="ten_dang_nhap" HeaderText="Tên ĐN" SortExpression="ten_dang_nhap" />
                <asp:TemplateField HeaderText="Dịch vụ">
                    <ItemTemplate>
                        <asp:DropDownList ID="ddl_uDV" runat="server" DataSourceID="EntityDataSource_DV"
                            DataTextField="ten_dich_vu" DataValueField="id_dich_vu" SelectedValue='<%# Bind("ma_dich_vu") %>'>
                        </asp:DropDownList>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:DropDownList ID="ddl_uDV1" runat="server" DataSourceID="EntityDataSource_DV"
                            DataTextField="ten_dich_vu" DataValueField="id_dich_vu" SelectedValue='<%# Bind("ma_dich_vu") %>'>
                        </asp:DropDownList>
                    </EditItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Tình trạng">
                    <ItemTemplate>
                        <asp:DropDownList ID="ddl_uStatus" runat="server" DataSourceID="EntityDataSource_Status"
                            DataTextField="ten_tinh_trang" DataValueField="ma_tinh_trang_dat_xe" SelectedValue='<%# Bind("ma_tinh_trang_dat_xe") %>'>
                        </asp:DropDownList>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="PT lái">
                    <ItemTemplate>
                        <asp:DropDownList ID="ddl_uPTL" runat="server" DataSourceID="EntityDataSource_PTL"
                            DataTextField="ten_phuong_thuc" DataValueField="ma_phuong_thuc" SelectedValue='<%# Bind("phuong_thuc_lai") %>'>
                        </asp:DropDownList>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="so_cho" HeaderText="Số chỗ" SortExpression="so_cho" />
                <asp:BoundField DataField="so_luong_xe" HeaderText="SL xe" SortExpression="so_luong_xe" />
                <asp:BoundField DataField="tu_ngay" HeaderText="Từ ngày" DataFormatString="{0:d}"  ApplyFormatInEditMode="true"
                    SortExpression="tu_ngay" />
                <asp:BoundField DataField="den_ngay" HeaderText="Đến ngày" DataFormatString="{0:d}"  ApplyFormatInEditMode="true"
                    SortExpression="den_ngay" />
                <asp:BoundField DataField="gio_don" HeaderText="Giờ đón" SortExpression="gio_don" />
                <asp:BoundField DataField="dia_diem_don" HeaderText="Địa điểm đón" SortExpression="dia_diem_don" />
                <asp:BoundField DataField="ghi_chu" HeaderText="Ghi chú" SortExpression="ghi_chu" />
                <asp:TemplateField HeaderText="Lộ trình">
                    <ItemTemplate>
                        <asp:DropDownList ID="ddl_uLT" runat="server" DataSourceID="EntityDataSource_LT"
                            DataTextField="ten_lo_trinh" DataValueField="ma_lo_trinh" SelectedValue='<%# Bind("ma_lo_trinh") %>'>
                        </asp:DropDownList>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:DropDownList ID="ddl_uLT1" runat="server" DataSourceID="EntityDataSource_LT"
                            DataTextField="ten_lo_trinh" DataValueField="ma_lo_trinh" SelectedValue='<%# Bind("ma_lo_trinh") %>'>
                        </asp:DropDownList>
                    </EditItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Miền">
                    <ItemTemplate>
                        <asp:DropDownList ID="ddl_uMien" runat="server" DataSourceID="EntityDataSource_Mien"
                            DataTextField="ten_mien" DataValueField="ma_mien" SelectedValue='<%# Bind("ma_mien") %>'>
                        </asp:DropDownList>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:DropDownList ID="ddl_uMien1" runat="server" DataSourceID="EntityDataSource_Mien"
                            DataTextField="ten_mien" DataValueField="ma_mien" SelectedValue='<%# Bind("ma_mien") %>'>
                        </asp:DropDownList>
                    </EditItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="ti_le_giam_gia" HeaderText="TL giảm giá" SortExpression="ti_le_giam_gia" />
                <asp:BoundField DataField="chi_phi_du_kien" HeaderText="CP dự kiến" SortExpression="chi_phi_du_kien" />
                <asp:BoundField DataField="tien_da_thanh_toan" HeaderText="Tiền đã TT" SortExpression="tien_da_thanh_toan" />
            </Columns>
            <FooterStyle BackColor="#7FB308" Font-Bold="True" ForeColor="White" />
            <HeaderStyle BackColor="#7FB308" Font-Bold="True" ForeColor="White" />
            <PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
            <RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
            <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
            <SortedAscendingCellStyle BackColor="#FDF5AC" />
            <SortedAscendingHeaderStyle BackColor="#4D0000" />
            <SortedDescendingCellStyle BackColor="#FCF6C0" />
            <SortedDescendingHeaderStyle BackColor="#820000" />
        </asp:GridView>
        <asp:EntityDataSource ID="EntityDataSource_Rersv" runat="server" ConnectionString="name=transportEntities"
            DefaultContainerName="transportEntities" EnableDelete="True" EnableFlattening="False"
            EnableInsert="True" EnableUpdate="True" EntitySetName="chi_tiet_dat_xe" EntityTypeFilter="chi_tiet_dat_xe"
            Where="it.ma_dich_vu = CASE WHEN @DV = '-1' THEN  it.ma_dich_vu ELSE @DV END
            AND it.ma_tinh_trang_dat_xe = CASE WHEN @Status = '-1' THEN  it.ma_tinh_trang_dat_xe ELSE @Status END
            AND it.phuong_thuc_lai = CASE WHEN @PTL = '-1' THEN  it.phuong_thuc_lai ELSE @PTL END
            AND it.ma_lo_trinh = CASE WHEN @LT = '-1' THEN  it.ma_lo_trinh ELSE @LT END
            AND it.ma_mien = CASE WHEN @Mien = '-1' THEN  it.ma_mien ELSE @Mien END">
            <WhereParameters>
                <asp:ControlParameter ControlID="ddl_DV" Type="String" Name="DV" PropertyName="SelectedValue" />
            </WhereParameters>
            <WhereParameters>
                <asp:ControlParameter ControlID="ddl_Status" Type="String" Name="Status" PropertyName="SelectedValue" />
            </WhereParameters>
            <WhereParameters>
                <asp:ControlParameter ControlID="ddl_PTL" Type="String" Name="PTL" PropertyName="SelectedValue" />
            </WhereParameters>
            <WhereParameters>
                <asp:ControlParameter ControlID="ddl_LT" Type="String" Name="LT" PropertyName="SelectedValue" />
            </WhereParameters>
            <WhereParameters>
                <asp:ControlParameter ControlID="ddl_Mien" Type="String" Name="Mien" PropertyName="SelectedValue" />
            </WhereParameters>
        </asp:EntityDataSource>
        <asp:QueryExtender ID="qeSearch1" runat="server" TargetControlID="EntityDataSource_Rersv">
            <asp:SearchExpression DataFields="id" SearchType="Contains">
                <asp:ControlParameter ControlID="txt_ID" />
            </asp:SearchExpression>
            <asp:SearchExpression DataFields="ten_dang_nhap" SearchType="Contains">
                <asp:ControlParameter ControlID="txt_Username" />
            </asp:SearchExpression>
            <asp:OrderByExpression DataField="ngay_dat" Direction="Ascending" />
        </asp:QueryExtender>
    </div>
    <p>
        <b>Tính toán và cập nhật tự động chi phí dự kiến:</b>
        <asp:Button ID="btn_Calculate" runat="server" Text="Tính" OnClick="btn_Calculate_Click" />
    </p>
    <p>
        <b>Duyệt đặt xe:</b>
        <asp:Button ID="btn_Confirm" runat="server" Text="Duyệt" OnClick="btn_Confirm_Click" />
    </p>
    <div>
        <b>B - DANH SÁCH XE ĐẶT</b>
    </div>
    <p>
        <asp:HyperLink ID="HyperLink_Xe" Target="_blank" runat="server" Text="Xem thông tin xe trống"
            NavigateUrl="~/Admin/TraCuuXe.aspx">
        </asp:HyperLink>
    </p>
    <p>
        <b>Mã đặt xe:</b>
        <asp:TextBox ID="txt_MDX" runat="server"></asp:TextBox>
        <b>Biển số xe:</b>
        <asp:TextBox ID="txt_BSX" runat="server"></asp:TextBox>
        <asp:Button ID="btn_Search2" runat="server" Text="Tìm" />
    </p>
    <p>
        <asp:GridView ID="GridView_Detail" runat="server" AllowPaging="True" AutoGenerateColumns="False"
            CellPadding="4" DataKeyNames="ma_so_dat_xe,bien_so" CellSpacing="4" DataSourceID="EntityDataSource_Detail"
            ForeColor="#333333" GridLines="None">
            <AlternatingRowStyle BackColor="White" />
            <Columns>
                <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
                <asp:BoundField DataField="ma_so_dat_xe" HeaderText="Mã số đặt xe" ReadOnly="True"
                    SortExpression="ma_so_dat_xe" />
                <asp:BoundField DataField="bien_so" HeaderText="Biển số xe" ReadOnly="True" SortExpression="bien_so" />
                <asp:BoundField DataField="ghi_chu" HeaderText="Ghi chú" SortExpression="ghi_chu" />
            </Columns>
            <FooterStyle BackColor="#7FB308" Font-Bold="True" ForeColor="White" />
            <HeaderStyle BackColor="#7FB308" Font-Bold="True" ForeColor="White" />
            <PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
            <RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
            <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
            <SortedAscendingCellStyle BackColor="#FDF5AC" />
            <SortedAscendingHeaderStyle BackColor="#4D0000" />
            <SortedDescendingCellStyle BackColor="#FCF6C0" />
            <SortedDescendingHeaderStyle BackColor="#820000" />
        </asp:GridView>
        <asp:EntityDataSource ID="EntityDataSource_Detail" runat="server" ConnectionString="name=transportEntities"
            DefaultContainerName="transportEntities" EnableDelete="True" EnableFlattening="False"
            EnableInsert="True" EnableUpdate="True" EntitySetName="danh_sach_xe_dat" EntityTypeFilter="danh_sach_xe_dat">
        </asp:EntityDataSource>
        <asp:QueryExtender ID="qeSearch2" runat="server" TargetControlID="EntityDataSource_Detail">
            <asp:SearchExpression DataFields="ma_so_dat_xe" SearchType="Contains">
                <asp:ControlParameter ControlID="txt_MDX" />
            </asp:SearchExpression>
            <asp:SearchExpression DataFields="bien_so" SearchType="Contains">
                <asp:ControlParameter ControlID="txt_BSX" />
            </asp:SearchExpression>
            <asp:OrderByExpression DataField="ma_so_dat_xe" Direction="Ascending" />
        </asp:QueryExtender>
    </p>
    <p>
        <asp:DetailsView ID="DetailsView_Detail" runat="server" Height="50px" Width="125px"
            DefaultMode="Insert" AutoGenerateRows="False" BackColor="White" BorderColor="#CCCCCC"
            BorderStyle="None" BorderWidth="1px" CellPadding="4" DataKeyNames="ma_so_dat_xe,bien_so"
            DataSourceID="EntityDataSource_Detail" ForeColor="Black" GridLines="Horizontal"
            FieldHeaderStyle-Wrap="false" 
            oniteminserted="DetailsView_Detail_ItemInserted">
            <EditRowStyle BackColor="#7FB308" Font-Bold="True" ForeColor="White" />
            <Fields>
                <asp:BoundField DataField="ma_so_dat_xe" HeaderText="Mã số đặt xe" ReadOnly="True"
                    SortExpression="ma_so_dat_xe" />
                <asp:BoundField DataField="bien_so" HeaderText="Biển số xe" ReadOnly="True" SortExpression="bien_so" />
                <asp:BoundField DataField="ghi_chu" HeaderText="Ghi chú" SortExpression="ghi_chu" />
                <asp:CommandField ShowInsertButton="True" />
            </Fields>
            <FooterStyle BackColor="#CCCC99" ForeColor="Black" />
            <HeaderStyle BackColor="#333333" Font-Bold="True" ForeColor="White" />
            <PagerStyle BackColor="White" ForeColor="Black" HorizontalAlign="Right" />
        </asp:DetailsView>
    </p>
    <div>
        <b>C - PHÂN CÔNG TÀI XẾ</b>
    </div>
    <p>
        <asp:HyperLink ID="HyperLink_TaiXe" Target="_blank" runat="server" Text="Tra cứu thông tin tài xế chưa được phân công"
            NavigateUrl="~/Admin/TraCuuTaiXe.aspx">
        </asp:HyperLink>
    </p>
    <p>
        <b>Mã số đặt xe:</b>
        <asp:TextBox ID="txt_MaDatXe" runat="server"></asp:TextBox>
        <b>Biển số xe:</b>
        <asp:TextBox ID="txt_BienSoXe" runat="server"></asp:TextBox>
        <b>Mã tài xế:</b>
        <asp:TextBox ID="txt_MaTaiXe" runat="server"></asp:TextBox>
        <asp:Button ID="btn_Search3" runat="server" Text="Tìm" />
    </p>
    <p>
        <asp:GridView ID="GridView_PhanCong" runat="server" AllowPaging="True" AutoGenerateColumns="False"
            CellPadding="4" DataKeyNames="ma_dat_xe,bien_so_xe" CellSpacing="4" DataSourceID="EntityDataSource_PhanCong"
            ForeColor="#333333" GridLines="None">
            <AlternatingRowStyle BackColor="White" />
            <Columns>
                <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
                <asp:BoundField DataField="ma_dat_xe" HeaderText="Mã số đặt xe" ReadOnly="True" SortExpression="ma_dat_xe" />
                <asp:BoundField DataField="bien_so_xe" HeaderText="Biển số xe" ReadOnly="True" SortExpression="bien_so_xe" />
                <asp:BoundField DataField="ma_tai_xe" HeaderText="Mã tài xế" SortExpression="ma_tai_xe" />
            </Columns>
            <FooterStyle BackColor="#7FB308" Font-Bold="True" ForeColor="White" />
            <HeaderStyle BackColor="#7FB308" Font-Bold="True" ForeColor="White" />
            <PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
            <RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
            <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
            <SortedAscendingCellStyle BackColor="#FDF5AC" />
            <SortedAscendingHeaderStyle BackColor="#4D0000" />
            <SortedDescendingCellStyle BackColor="#FCF6C0" />
            <SortedDescendingHeaderStyle BackColor="#820000" />
        </asp:GridView>
        <asp:EntityDataSource ID="EntityDataSource_PhanCong" runat="server" ConnectionString="name=transportEntities"
            DefaultContainerName="transportEntities" EnableDelete="True" EnableFlattening="False"
            EnableInsert="True" EnableUpdate="True" EntitySetName="phan_cong" EntityTypeFilter="phan_cong">
        </asp:EntityDataSource>
        <asp:QueryExtender ID="qeSearch3" runat="server" TargetControlID="EntityDataSource_PhanCong">
            <asp:SearchExpression DataFields="ma_dat_xe" SearchType="Contains">
                <asp:ControlParameter ControlID="txt_MaDatXe" />
            </asp:SearchExpression>
            <asp:SearchExpression DataFields="bien_so_xe" SearchType="Contains">
                <asp:ControlParameter ControlID="txt_BienSoXe" />
            </asp:SearchExpression>
            <asp:SearchExpression DataFields="ma_tai_xe" SearchType="Contains">
                <asp:ControlParameter ControlID="txt_MaTaiXe" />
            </asp:SearchExpression>
            <asp:OrderByExpression DataField="ma_dat_xe" Direction="Ascending" />
        </asp:QueryExtender>
    </p>
    <p>
        <asp:DetailsView ID="DetailsView_PhanCong" runat="server" Height="50px" Width="125px"
            AutoGenerateRows="False" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None"
            BorderWidth="1px" CellPadding="4" DataKeyNames="ma_dat_xe,bien_so_xe" DataSourceID="EntityDataSource_PhanCong"
            DefaultMode="Insert" ForeColor="Black" GridLines="Horizontal" 
            FieldHeaderStyle-Wrap="false" 
            oniteminserted="DetailsView_PhanCong_ItemInserted">
            <EditRowStyle BackColor="#7FB308" Font-Bold="True" ForeColor="White" />

<FieldHeaderStyle Wrap="False"></FieldHeaderStyle>
            <Fields>
                <asp:BoundField DataField="ma_dat_xe" HeaderText="Mã số đặt xe" ReadOnly="True" SortExpression="ma_dat_xe" />
                <asp:BoundField DataField="bien_so_xe" HeaderText="Biển số xe" ReadOnly="True" SortExpression="bien_so_xe" />
                <asp:BoundField DataField="ma_tai_xe" HeaderText="Mã tài xế" SortExpression="ma_tai_xe" />
                <asp:CommandField ShowInsertButton="True" />
            </Fields>
            <FooterStyle BackColor="#CCCC99" ForeColor="Black" />
            <HeaderStyle BackColor="#333333" Font-Bold="True" ForeColor="White" />
            <PagerStyle BackColor="White" ForeColor="Black" HorizontalAlign="Right" />
        </asp:DetailsView>
    </p>
</asp:Content>
